/**
 * @param {*} searchUser 获取用户
 * @param {*} deleteUser 删除某个用户
 * @param {*} updateUser 修改某个用户

 * @param {*} searchOrder 获取订单

 * @param {*} searchProduct 获取课程
 * @param {*} updateProduct 修改课程
 * @param {*} deleteProduct 删除课程
 * @param {*} addProduct 创建课程

 * @param {*} uploadCheck 获取视频字节数
 * @param {*} uploadChunk 分片上传
 *
 * @param {*} flowStat 流量访问统计
 * @param {*} deviceType 终端类型分布
 * @param {*} referer top网站来源
 * @param {*} region 地域分布
 * @param {*} todayData 今日实时数据
 * @param {*} topPurchase 近期销售占比
 * @param {*} orderTrend 订单量趋势统计
 * @param {*} userTrend 用户量趋势统计
 */
const AdminService = require('../service/AdminService')

const BarrageController = {
    // 用户相关
    async searchUser(req, res) {
        let {condition} = req.params
        let {page, size} = req.query
        let handleRes = await AdminService.searchUser({condition, page, size})
        res.send(handleRes)
    },
    async deleteUser(req, res) {
        let {id} = req.params
        let handleRes = await AdminService.deleteUser(id)
        res.send(handleRes)
    },
    async updateUser(req, res) {
        let {id} = req.params
        let {updated_details} = req.body
        let handleRes = await AdminService.updateUser(id, updated_details)
        res.send(handleRes)
    },
    async searchTeacher(req, res) {
        let {page, size} = req.query
        let handleRes = await AdminService.searchTeacher({page, size})
        res.send(handleRes)
    },
    // 订单相关
    async searchOrder(req, res) {
        let {condition} = req.params
        let {page, size, gmt_start, gmt_end} = req.query
        let handleRes = await AdminService.searchOrder({condition, page, size, gmt_start, gmt_end})
        res.send(handleRes)
    },
    // 课程相关
    async searchProduct(req, res) {
        let {condition} = req.params
        let {page, size} = req.query
        let handleRes = await AdminService.searchProduct({condition, page, size})
        res.send(handleRes)
    },
    async updateProduct(req, res) {
        let {id} = req.params
        let {updated_details} = req.body
        let handleRes = await AdminService.updateProduct(id, updated_details)
        res.send(handleRes)
    },
    async deleteProduct(req, res) {
        let {id} = req.params
        let handleRes = await AdminService.deleteProduct(id)
        res.send(handleRes)
    },
    async addProduct(req, res) {
        let {new_details, chapters} = req.body
        let handleRes = await AdminService.addProduct({new_details, chapters, file: req.file})
        res.send(handleRes)
    },
    async getChaptersAndEpisodes(req, res) {
        let {id} = req.params
        let handleRes = await AdminService.getChaptersAndEpisodes(id)
        res.send(handleRes)
    },
    // 视频相关
    async uploadCheck(req, res) {
        let {hash, type} = req.body
        let handleRes = await AdminService.uploadCheck({hash, type})
        res.send(handleRes)
    },
    async uploadChunk(req, res) {
        let {size, hash, title, type} = req.body
        let handleRes = await AdminService.uploadChunk({size, hash, title, type, chunk: req.file})
        res.send(handleRes)
    },
    async uploadHWCloud(req, res) {
        let {type, title, episodeId} = req.body
        let handleRes = await AdminService.uploadHWCloud({type, title, episodeId})
        res.send(handleRes)
    },
    async flowStat(req, res) {
        let handleRes = await AdminService.flowStat()
        res.send(handleRes)
    },
    async deviceType(req, res) {
        let handleRes = await AdminService.deviceType()
        res.send(handleRes)
    },
    async referer(req, res) {
        let handleRes = await AdminService.referer()
        res.send(handleRes)
    },
    async region(req, res) {
        let handleRes = await AdminService.region()
        res.send(handleRes)
    },
    async todayData(req, res) {
        let handleRes = await AdminService.todayData()
        res.send(handleRes)
    },
    async topPurchase(req, res) {
        let handleRes = await AdminService.topPurchase()
        res.send(handleRes)
    },
    async orderTrend(req, res) {
        let handleRes = await AdminService.orderTrend()
        res.send(handleRes)
    },
    async userTrend(req, res) {
        let handleRes = await AdminService.userTrend()
        res.send(handleRes)
    },
    async uploadImage(req, res) {
        let handleRes = await AdminService.uploadImage(req.file)
        res.send(handleRes)
    },
}

module.exports = BarrageController